package Actions;

import com.opensymphony.xwork2.ActionSupport;
import homework9.Bean.School;
import homework9.Bean.Student;
import org.hibernate.Session;
import org.hibernate.SessionFactory;
import org.hibernate.cfg.Configuration;
import org.hibernate.query.Query;

import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

/**
 * @author CoderXshuai
 */
public class TestAction extends ActionSupport {
    private static final SessionFactory FACTORY;
    private String id;
    static {
        Configuration configuration = new Configuration();
        configuration.configure();
        FACTORY = configuration.buildSessionFactory();
    }

//    private List<School> schoolList = new ArrayList<>();
    private List<Student> stulist = new ArrayList<>();
    private Map<Student, List<School>> listMap = new HashMap<>();

    public static Session getSession() {
        return FACTORY.openSession();
    }

//    public List<School> getSchoolList() {
//        return schoolList;
//    }
//
//    public void setSchoolList(List<School> schoolList) {
//        this.schoolList = schoolList;
//    }

    public List<Student> getStulist() {
        return stulist;
    }

    public void setStulist(List<Student> stulist) {
        this.stulist = stulist;
    }

    public Map<Student, List<School>> getListMap() {
        return listMap;
    }

    public void setListMap(Map<Student, List<School>> listMap) {
        this.listMap = listMap;
    }

    @Override
    public String execute() throws Exception {
//        Session session = getSession();
//        Query studentQuery = session.createQuery("from Student ");
//        stulist = studentQuery.list();
//        for (Student student:stulist){
//            listMap.put(student,student.getSchoolList());
//        }
//        session.beginTransaction().commit();
        id="5";
        return SUCCESS;
    }

    public String getId() {
        return id;
    }

    public void setId(String id) {
        this.id = id;
    }
}
